package com.yimils.core.goods.controller;

import com.yimils.core.common.dto.RspBase;
import com.yimils.core.goods.dto.SupplierAddReq;
import com.yimils.core.goods.dto.SupplierUpdateReq;
import com.yimils.core.goods.serivce.SupplierService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Validated
public class SupplierController {
    @Resource(name = "supplierService")
    SupplierService supplierService;

    @PostMapping("/supplier/save")
    public RspBase saveSupplier(@RequestBody SupplierAddReq supplierAddReq) {
        if (supplierService.saveSupplier(supplierAddReq)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @PutMapping("/supplier/update")
    public RspBase updateSupplier(@RequestBody SupplierUpdateReq supplierUpdateReq) {
        if (supplierService.updateSupplier(supplierUpdateReq)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @DeleteMapping("/supplier/delete")
    public RspBase deleteSupplier(List<Long> supplierIds) {
        if (supplierService.deleteSupplier(supplierIds)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @GetMapping("/supplier/list")
    public RspBase listSupplier() {
        RspBase rsp = RspBase.OK();
        rsp.put("data", supplierService.listSupplier());
        return rsp;
    }

    @PutMapping("/supplier/audit")
    public RspBase audit(Long supplierId, String auditState) {
        if (supplierService.audit(supplierId, auditState)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }

    @PutMapping("/supplier/isAble")
    public RspBase isAble(Long supplierId, String isAbleState) {
        if (supplierService.isAble(supplierId, isAbleState)) {
            return RspBase.OK("成功");
        }
        return RspBase.OK("失败");
    }
}
